// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-/* exported addContextMenu */
+/* exported addContextMenu CapsLockWarning */
-const { Clutter, Shell, St } = imports.gi;
+const { Clutter, GObject, Pango, Shell, St } = imports.gi;
const BoxPointer = imports.ui.boxpointer;
const Main = imports.ui.main;
entry._menuManager = null;
});
}
+
+var CapsLockWarning = GObject.registerClass(
+class CapsLockWarning extends St.Label {
+ _init(params) {
+ let defaultParams = { style_class: 'prompt-dialog-error-label' };
+ super._init(Object.assign(defaultParams, params));
+
+ this.text = _('Caps lock is on.');
+
+ this._keymap = Clutter.get_default_backend().get_keymap();
+
+ this.connect('notify::mapped', () => {
+ if (this.is_mapped()) {
+ this.stateChangedId = this._keymap.connect('state-changed',
+ this._updateCapsLockWarningOpacity.bind(this));
+ } else {
+ this._keymap.disconnect(this.stateChangedId);
+ this.stateChangedId = 0;
+ }
+
+ this._updateCapsLockWarningOpacity();
+ });
+
+ this.connect('destroy', () => {
+ if (this.stateChangedId > 0)
+ this._keymap.disconnect(this.stateChangedId);
+ });
+
+ this.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
+ this.clutter_text.line_wrap = true;
+ }
+
+ _updateCapsLockWarningOpacity() {
+ let capsLockOn = this._keymap.get_caps_lock_state();
+ this.opacity = capsLockOn ? 255 : 0;
+ }
+});